﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using BLL;
using Model;
using Common;

namespace API.Controllers
{
    [RoutePrefix("api/ExperienceCom")]
    public class ExperienceComController : ApiController
    {
        B_ExperienceCom _bec;
        public ExperienceComController()
        {
            _bec = new B_ExperienceCom();
        }

        /// <summary>
        /// 获取所有用户简历的经历详情：分页
        /// </summary>
        /// <returns></returns>
        [Route("GetAll")]
        [HttpGet]
        public IHttpActionResult GetAll(int page,int size)
        {
            var detail = new B_ExperienceDetail().GetAll();
            var type = new B_ExperienceType().GetAll();
            var data = from ec in _bec.GetAll()
                       join ed in detail on ec.EDID equals ed.EDID
                       join et in type on ed.ETypeID equals et.ETypeID
                       select new Param_ExperienceCom
                       {
                           ID = ec.ID,
                           EDID = ec.EDID,
                           TemplateID = ec.TemplateID,
                           ETypeID = ed.ETypeID,
                           EName = et.EName,
                           EDOne = ed.EDOne,
                           EDTwo = ed.EDTwo,
                           EDThressTime = ed.EDThressTime,
                           EDThressOutTime = ed.EDThressOutTime,
                           EDFour = ed.EDFour,
                           EDFiveDescribe = ed.EDFiveDescribe,
                           IsOnTrue = ed.IsOnTrue
                       };

            return Ok(new Result<List<Param_ExperienceCom>>()
            {
                Data = data.Skip((page-1)*size).Take(size).ToList(),
                Msg=data.Count().ToString()
            });
        }

        /// <summary>
        /// 获取所有用户简历的经历详情
        /// </summary>
        /// <returns></returns>
        [Route("GetAll")]
        [HttpGet]
        public IHttpActionResult GetAll()
        {
            var detail = new B_ExperienceDetail().GetAll();
            var type = new B_ExperienceType().GetAll();
            var data = from ec in _bec.GetAll()
                       join ed in detail on ec.EDID equals ed.EDID
                       join et in type on ed.ETypeID equals et.ETypeID
                       select new Param_ExperienceCom
                       {
                           ID = ec.ID,
                           EDID = ec.EDID,
                           TemplateID = ec.TemplateID,
                           ETypeID = et.ETypeID,
                           EName = et.EName,
                           EDOne = ed.EDOne,
                           EDTwo = ed.EDTwo,
                           EDThressTime = ed.EDThressTime,
                           EDThressOutTime = ed.EDThressOutTime,
                           EDFour = ed.EDFour,
                           EDFiveDescribe = ed.EDFiveDescribe,
                           IsOnTrue = ed.IsOnTrue
                       };

            return Ok(new Result<List<Param_ExperienceCom>>() {
                Data=data.ToList()
            });
        }
    }
}
